Skip to content

geoip: T5746: Download ASN database - #1215

Merged
c-po merged 2 commits into
vyos:rollingfrom
sarthurdev:geoip
Jun 18, 2026
Merged

geoip: T5746: Download ASN database#1215
c-po merged 2 commits into
vyos:rollingfrom
sarthurdev:geoip

Conversation

@sarthurdev

@sarthurdev sarthurdev commented Jun 4, 2026

Copy link
Copy Markdown
Member

Change summary

Download initial GeoIP ASN database for system image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

How to test / Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • GeoIP database now includes autonomous system number (ASN) data alongside country information for enhanced IP geolocation capabilities.
  • Improvements

    • Enhanced download reliability with improved error handling and per-dataset failure detection.

Walkthrough

The chroot hook script now downloads both DB-IP country-lite and ASN-lite datasets. The country download switches from wget to curl with silent/fail-fast/redirect flags; a new ASN_URL/ASN_OUT_PATH block mirrors the same pattern. Each download creates its output directory, checks exit status, prints a dataset-specific error, and removes the partial file on failure. A comment is added to the excludes file.

Changes

GeoIP Download Script and Excludes

Layer / File(s) Summary
ASN download, curl migration, and error handling
data/live-build-config/hooks/live/40-init-geoip-database.chroot, data/live-build-config/rootfs/excludes
Replaces wget with curl -sSfL for country-lite, adds ASN_URL/ASN_OUT_PATH variables and a mirrored download block with mkdir -p, per-dataset failure messages and partial-file cleanup. Adds a T7926 comment in the excludes list.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding ASN database download functionality to the GeoIP initialization script.
Description check ✅ Passed The description is directly related to the changeset, clearly stating the intent to download the initial GeoIP ASN database for the system image.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread data/live-build-config/hooks/live/40-init-geoip-database.chroot Outdated
@sarthurdev
sarthurdev marked this pull request as ready for review June 17, 2026 08:46
@sarthurdev
sarthurdev requested a review from c-po June 17, 2026 08:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@data/live-build-config/hooks/live/40-init-geoip-database.chroot`:
- Around line 16-19: The GeoIP download error handling at lines 16-19 logs the
failure and removes the partial file but fails to exit with a non-zero status,
allowing the script to continue and potentially leave the image in a partially
initialized state. After the rm $OUT_PATH command in the error handling block,
add exit 1 to terminate the script with a failure status. This same fix needs to
be applied to the other GeoIP download failure path mentioned at lines 24-27 as
well, ensuring all download failure paths terminate immediately with a non-zero
exit code.

In `@data/live-build-config/rootfs/excludes`:
- Around line 48-49: The comment on line 48 labeled "T7926: VyOS GeoIP database
location" is misleading because the exclusion pattern
`var/cache/!(cracklib|vyos)` actually preserves the `/var/cache/vyos` directory
(the vyos cache directory), not the GeoIP database itself which is located
elsewhere at `/usr/share/vyos-geoip`. Reword the comment next to the exclusion
pattern to explicitly clarify that it preserves the vyos cache directory by
changing the description to something that accurately reflects why
`/var/cache/vyos` is being kept in the exclusion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: b0af7fe2-26ee-4709-9dc1-c66093123b3b

📥 Commits

Reviewing files that changed from the base of the PR and between c5e5c86 and ea19696.

📒 Files selected for processing (2)
  • data/live-build-config/hooks/live/40-init-geoip-database.chroot
  • data/live-build-config/rootfs/excludes
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • ansible/ansible (manual)
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test_config_load
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary

Comment on lines 16 to 19
if [ $? -ne 0 ]; then
echo "Failed to download GeoIP database"
echo "Failed to download GeoIP country-code database"
rm $OUT_PATH
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail fast when either GeoIP download fails.

Right now the hook logs and removes the partial file, but still continues to Line 30. That can leave the image in a partially initialized state. Make each failure path terminate with non-zero status.

Suggested patch
-mkdir -p $(dirname $OUT_PATH)
-curl -sSfL -o $OUT_PATH $URL
-
-if [ $? -ne 0 ]; then
+mkdir -p "$(dirname "$OUT_PATH")"
+if ! curl -sSfL -o "$OUT_PATH" "$URL"; then
     echo "Failed to download GeoIP country-code database"
-    rm $OUT_PATH
+    rm -f "$OUT_PATH"
+    exit 1
 fi
 
-mkdir -p $(dirname $ASN_OUT_PATH)
-curl -sSfL -o $ASN_OUT_PATH $ASN_URL
-
-if [ $? -ne 0 ]; then
+mkdir -p "$(dirname "$ASN_OUT_PATH")"
+if ! curl -sSfL -o "$ASN_OUT_PATH" "$ASN_URL"; then
     echo "Failed to download GeoIP ASN database"
-    rm $ASN_OUT_PATH
+    rm -f "$ASN_OUT_PATH"
+    exit 1
 fi

Also applies to: 24-27

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@data/live-build-config/hooks/live/40-init-geoip-database.chroot` around lines
16 - 19, The GeoIP download error handling at lines 16-19 logs the failure and
removes the partial file but fails to exit with a non-zero status, allowing the
script to continue and potentially leave the image in a partially initialized
state. After the rm $OUT_PATH command in the error handling block, add exit 1 to
terminate the script with a failure status. This same fix needs to be applied to
the other GeoIP download failure path mentioned at lines 24-27 as well, ensuring
all download failure paths terminate immediately with a non-zero exit code.

Comment on lines +48 to 49
# T7926: VyOS GeoIP database location
var/cache/!(cracklib|vyos)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify the T7926 comment to match the actual path context.

Line 48 says “VyOS GeoIP database location” in a /var/cache exclusion block, while the downloader writes to /usr/share/vyos-geoip in data/live-build-config/hooks/live/40-init-geoip-database.chroot (Lines 8 and 11). Please reword this to explicitly describe why /var/cache/vyos is preserved here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@data/live-build-config/rootfs/excludes` around lines 48 - 49, The comment on
line 48 labeled "T7926: VyOS GeoIP database location" is misleading because the
exclusion pattern `var/cache/!(cracklib|vyos)` actually preserves the
`/var/cache/vyos` directory (the vyos cache directory), not the GeoIP database
itself which is located elsewhere at `/usr/share/vyos-geoip`. Reword the comment
next to the exclusion pattern to explicitly clarify that it preserves the vyos
cache directory by changing the description to something that accurately
reflects why `/var/cache/vyos` is being kept in the exclusion.

@github-actions

Copy link
Copy Markdown

CI integration 👍 passed!

Details

CI logs

  • Config tests 👍 passed

@sever-sever sever-sever left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Download GeoIP ASN Database in live-build hook

@c-po c-po left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Download GeoIP ASN database to image

@c-po
c-po merged commit bd827e7 into vyos:rolling Jun 18, 2026
12 of 14 checks passed
@vyos-bot vyos-bot Bot added mirror-initiated This PR initiated for mirror sync workflow mirror-completed and removed mirror-initiated This PR initiated for mirror sync workflow labels Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants